package com.jiawa.train.member.Controller;

import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.member.req.MemberLoginReq;
import com.jiawa.train.member.req.MemberRegisterReq;
import com.jiawa.train.member.req.MemberSendCodeReq;
import com.jiawa.train.member.resp.MemberLoginResp;
import com.jiawa.train.member.service.IMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 会员 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-09-06
 */
@RestController
@RequestMapping("/member")
@RequiredArgsConstructor
public class MemberController {
    private final IMemberService memberService;

    @PostMapping("/register")
    public CommonResp<Long> register(@Validated @RequestBody MemberRegisterReq mobile) {
        return memberService.register(mobile.getMobile());
    }

    @PostMapping("/send-code")
    public CommonResp<String> code(@Validated @RequestBody MemberSendCodeReq mobile) {
        memberService.sendCode(mobile.getMobile());
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Validated @RequestBody MemberLoginReq req) {
        MemberLoginResp memberLoginResp = memberService.login(req);
        return new CommonResp<>(memberLoginResp);
    }

}
